#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python常用模块库 
@File ：size_policy.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2025/2/21 上午8:58 
"""

from pathlib import Path
from typing import List, Dict


class SizePolicy:
	def __init__(self, max_size_gb: float):
		self.max_size = max_size_gb * 1024 ** 3  # 转换为字节

	def apply(self, files: List[Dict]) -> List[Path]:
		"""容量清理策略"""
		total = sum(f["size"] for f in files)
		if total <= self.max_size:
			return []

		# 按修改时间排序（旧文件优先）
		sorted_files = sorted(files, key=lambda x: x["mtime"])
		to_delete = []
		current_size = total

		for f in sorted_files:
			if current_size <= self.max_size:
				break
			to_delete.append(f["path"])
			current_size -= f["size"]

		return to_delete
